/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package todotask.entities;

import java.util.Calendar;
import todotask.Database.Data;

/**
 *
 * @author dakota
 */
public class Task {

    private String title;
    private String description;
    private Integer time;
    private Calendar startDate;
    private Calendar finishDate;
    private Category category;
    private Status status;
    private String id;
    private Data db;

    public void newData() {
        db = new Data();
    }

    @Override
    public String toString() {
        return "<task>"
                + "<title>" + getTitle() + "</title>"
                + "<description>" + getDescription() + "</description>"
                + "<time>" + getTime() + "</time>"
                + "<startDate>" + getStartDate() + "</startDate>"
                + "<finishDate>" + getFinishDate() + "</finishDate>"
                + "<category>" + getCategory().getNombre() + "</category>"
                + "<status>" + getStatus().getStatus() + "</status>"
                + "</task>";
    }

    public Task(String title, String description, Integer time, Calendar startDate, Calendar finishDate, Category category, Status status, String id) {
        this.title = title;
        this.description = description;
        this.time = time;
        this.startDate = startDate;
        this.finishDate = finishDate;
        this.category = category;
        this.status = status;
        this.id = id;
        newData();
    }

    public Task() {
        setTitle("");
        setDescription("");
        setTime(0);
        setStartDate(Calendar.getInstance());
        setFinishDate(null);
        setCategory(new Category());
        setStatus(new Status());
        setId("0");
        newData();
    }

    public Task(Task t) {
        setTitle(t.getTitle());
        setDescription(t.getDescription());
        setTime(t.getTime());
        setStartDate(t.getStartDate());
        setFinishDate(t.getFinishDate());
        setCategory(t.getCategory());
        setStatus(t.getStatus());
        setId(t.getId());
        newData();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Calendar getFinishDate() {
        if (finishDate != null) {
            return finishDate;
        } else {
            return Calendar.getInstance();
        }
    }

    public void setFinishDate(Calendar finishDate) {
        if (finishDate != null) {
            this.finishDate = finishDate;
            db.setFinished(this);
        }
    }

    public Calendar getStartDate() {
        if (startDate != null) {
            return startDate;
        } else {
            return Calendar.getInstance();
        }
    }

    public void setStartDate(Calendar startDate) {
        this.startDate = startDate;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Integer getTime() {
        return time;
    }

    public void setTime(Integer time) {
        this.time = time;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}
